<template>
  <div class="user_order_withdraw">
    <el-container>
      <el-header>
        <header-item :item="tips"></header-item>
      </el-header>
      <el-main>
        <main-tools-item :toolsType="toolsType" :searchType="searchType" :defaultTime="defaultTime" @search='search'></main-tools-item>
        <main-spare-item @onClick=''></main-spare-item>
        <main-data-list-item :columns="columns" :dataList="dataList" :pager="page" @batchDelete='batchDelete' @currentChange='currentChange'>
          <el-table-column label="操作" slot="table_oper" min-width="160px" fixed="right">
            <template slot-scope="scope">
              <el-button v-if="scope.row.status =='1'" size="mini" type="success" @click="handleExamine(scope.$index, scope.row)">审核</el-button>
              <el-button v-if="scope.row.status =='1'" size="mini" type="" @click="handleReject(scope.$index, scope.row)">驳回</el-button>
            </template>
          </el-table-column>
        </main-data-list-item>
      </el-main>
    </el-container>
  </div>
</template>

<script>
  import {
    get,
    post,
    pat,
    del,
    common,
    getRefresh
  } from "../../../../api/api";
  import headerItem from "./../../Commons/headerItem.vue";
  import mainToolsItem from "./../../Commons/mainToolsItem.vue";
  import mainSpareItem from "./../../Commons/mainSpareItem.vue";
  import mainDataListItem from "./../../Commons/mainDataListItem.vue";
  export default {
    components: {
      headerItem,
      mainToolsItem,
      mainSpareItem,
      mainDataListItem
    },
    data() {
      return {
        tips: "提现订单",
        toolsType: 2,
        searchType: 8,
        sels: [],
        page: {
          pageNo: 1,
          limit: 10,
          sizes: [10, 50, 100],
          total: 0
        },
        columns: [{
            prop: 'id',
            label: '订单ID',
            width: '300px',
            align: 'center'
          },
          {
            prop: 'tradeNo',
            label: '三方支付流水号',
            width: '160px',
            align: 'center',
          },
          {
            prop: 'orderGoodsUserInfo',
            label: '用户',
            width: '160px',
            align: 'center'
          },
          {
            prop: 'totalPrice',
            label: '订单总金额',
            width: '160px',
            align: 'center'
          },
          {
            prop: 'rmb',
            label: '实际打款金额',
            width: '160px',
            align: 'center'
          },
          {
            prop: 'bankCardNo',
            label: '提现银行卡号',
            width: '160px',
            align: 'center'
          },
          {
            prop: 'withdrawName',
            label: '提现用户名',
            width: '160px',
            align: 'center'
          },
          {
            prop: 'bankName',
            label: '提现银行名称',
            width: '160px',
            align: 'center'
          },
          {
            prop: 'withdrawStatus',
            label: '订单状态',
            width: '',
            align: 'center'
          },
          {
            prop: 'createTime',
            label: '订单生成时间',
            width: '',
            align: 'center'
          },
          {
            prop: 'paySucTime',
            label: '订单付款时间',
            width: '',
            align: 'center'
          },
          {
            prop: 'completeTime',
            label: '订单完成时间',
            width: '',
            align: 'center'
          },
          {
            prop: 'refuseTime',
            label: '订单审核不通过时间',
            width: '',
            align: 'center'
          },
          {
            prop: 'cancelTime',
            label: '取消时间',
            width: '',
            align: 'center'
          },
          {
            prop: 'delTime',
            label: '订单删除时间',
            width: '',
            align: 'center'
          },
          {
            prop: 'checkUser',
            label: '后台审核用户',
            width: '160px',
            align: 'center'
          },
          {
            prop: 'remark',
            label: '订单备注信息',
            width: '200px',
            align: 'center'
          }
        ],
        dataList: [],
        loading: false,
        defaultTime: {
          startTime: '',
          endTime: ''
        },
        param: {
          phone: '',
          status: '',
          startTime: '',
          endTime: '',
          size: '10',
          current: '1'
        },
      };
    },
    methods: {
      //--------查询----------
      search(val) {
        this.param ={}
        this.param.phone = "";
        this.param.status = "";
        this.param.startTime = "";
        this.param.endTime = "";
        this.param.phone = val.phone;
        this.param.status = val.status;
        this.param.startTime = val.date[0];
        this.param.endTime = val.date[1];
        this.getUserOrderWithdrawList();
      },
      //--------审核----------
      handleExamine(index, row) {
        this.examineConfirm(row.id)
      },
      //--------驳回----------
      handleReject(index, row) {
        this.rejectConfirm(row.id)
      },
      //--------删除----------
      batchDelete(val) {
        console.log(val);
      },
      //-------分页----------
      currentChange(val) {
        this.param.current = "";
        this.param.current = val
        this.getUserOrderWithdrawList();
      },
      //获取list列表
      getUserOrderWithdrawList() {
        return new Promise((resolve, reject) => {
          var param = {};
          for (let key in this.param) {
            if (this.param[key] != null && this.param[key].length != 0) {
              param[key] = this.param[key]
            }
          }
          post("/order/selectXasUserOrderWithdraw", param).then(resdata => {
            let self = function () {
              this.$router.push({ path: '/home'});
            }.bind(this);
            let error = function () {
              alert(resdata.msg)
            }.bind(this);
            let success = function () {
              if (resdata.code == 1) {
                this.dataList = resdata.data.records;
                this.page.total = resdata.data.total;
              }
            }.bind(this);
            common(self)(error)(success)(resdata);
            resolve();
          });
        });
      },
      examineConfirm(id) {
        this.$confirm('确定审核, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          this.examineXasUserOrderWithdraw(id);
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消审核'
          });
        });
      },
      examineXasUserOrderWithdraw(id) {
        return new Promise((resolve, reject) => {
          post("/order/examineXasUserOrderWithdraw", {
            'id': id
          }).then(resdata => {
            let self = function () {
              getRefresh(this.examineXasUserOrderWithdraw);
            }.bind(this);
            let error = function () {
              alert(resdata.msg)
            }.bind(this);
            let success = function () {
              if (resdata.code == 1) {
                this.$message({
                  message: '审核成功！',
                  type: 'success',
                  duration: 5000,
                });
                this.getUserOrderWithdrawList();
              }
            }.bind(this);
            common(self)(error)(success)(resdata);
            resolve();
          });
        });
      },
      rejectConfirm(id) {
        this.$confirm('确定驳回, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          this.examineRejectXasUserOrderWithdraw(id);
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消驳回'
          });
        });
      },
      examineRejectXasUserOrderWithdraw(id) {
        return new Promise((resolve, reject) => {
          post("/order/examineRejectXasUserOrderWithdraw", {
            'id': id
          }).then(resdata => {
            let self = function () {
              getRefresh(this.examineXasUserOrderWithdraw);
            }.bind(this);
            let error = function () {
              alert(resdata.msg)
            }.bind(this);
            let success = function () {
              if (resdata.code == 1) {
                this.$message({
                  message: '审核成功！',
                  type: 'success',
                  duration: 5000,
                });
                this.getUserOrderWithdrawList();
              }
            }.bind(this);
            common(self)(error)(success)(resdata);
            resolve();
          });
        });
      },
    },
    async mounted() {
      this.param.startTime = this.defaultTime.startTime;
      this.param.endTime = this.defaultTime.endTime;
      await this.getUserOrderWithdrawList();
    },
    watch: {}
  };

</script>

<style lang="scss">
  .user_order_withdraw {
    background-color: white;
    font-size: 1.8rem;
    width: 100%;
    height: 100%;
    .el-container {
      height: 100%;
      .el-header,
      .el-footer {
        background-color: #F9FAFE;
        color: #333;
        text-align: center;
        line-height: 50px;
        height: 50px !important;
        .header-child {
          height: 50px;
          width: 100%;
          text-align: left;
          padding-left: 20px;
          background-color: #cbe9eb;
          border-bottom: 1px solid black;
          box-shadow: 0 5px 5px 0 rgba(0, 0, 0, 0.5);
        }
      }
      .el-main {
        box-shadow: 0 5px 5px 0px rgba(0, 0, 0, 0.5); // margin: 10px 20px;
        margin: 10px;
        background-color: #fff;
        color: #333;
        text-align: center;
        height: 100%;
      }
    }
  }

</style>
